package de.tum.in.oose.bumpers.control;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;

import de.tum.in.oose.bumpers.cars.Car;

/**
 * Our strategy is that the Upper car during a collision wins. 
 *
 */
public class SEteam12Collision extends CollisionStrategy {
	
	@Override
	public String getName() {
		return "SEteam12Collision";
	}	
	@Override
	public Car detectCollision(Car drivenCar, Car roboCar) {
		Point p1 = drivenCar.getPosition();
		Dimension d1 = drivenCar.getSize();
		Rectangle r1 = new Rectangle(p1, d1);
		r1.translate(p1.x / 8, p1.y / 8);
		r1.grow(-1 * d1.width / 4, -1 * d1.height / 4);

		Point p2 = roboCar.getPosition();
		Dimension d2 = roboCar.getSize();
		Rectangle r2 = new Rectangle(p2, d2);
		r2.translate(p2.x / 8, p2.y / 8);
		r2.grow(-1 * d2.width / 4, -1 * d2.height / 4);

		if (r1.intersects(r2)) {
			if (p1.y > p2.y) {
				return roboCar;
			} else {
				return drivenCar;
			}
		}
		return null;
	}
}
